<template>
<div style="width: 100%">

  <a-card class="card" :bordered="false">

    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="准考证号">
              <a-input placeholder="请输入..." v-model="queryParam.ksbh"/>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="姓名">
              <a-input placeholder="请输入..." v-model="queryParam.ksxm"/>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="招生年度">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zsnj">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <!-- <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="报考院系">
              <a-select :allowClear="true"  showSearch optionFilterProp="children" :filterOption="filterOption"  v-model="queryParam.bkyxsm" @change="yxChange">
                <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwh+'-'+i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="报考专业">
              <a-select :allowClear="true" showSearch optionFilterProp="children" :filterOption="filterOption" v-model="queryParam.bkzydm">
                <a-select-option v-for="i in selectMenu.zy" :key="i.zyh" :value="i.zyh">{{ i.zyh+'-'+i.zymc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col> -->
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="调剂院系">
              <a-select :allowClear="true" showSearch optionFilterProp="children" :filterOption="filterOption" v-model="queryParam.tjyxdm" @change="yxChange2">
                <a-select-option v-for="i in selectMenu.tjyx" :key="i.id" :value="i.dwh">{{ i.dwh+'-'+i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="调剂专业">
              <a-select :allowClear="true" showSearch optionFilterProp="children" :filterOption="filterOption" v-model="queryParam.tjzydm">
                <a-select-option v-for="i in selectMenu.tjzy" :key="i.zyh" :value="i.zyh">{{ i.zyh+'-'+i.zymc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          </template>
          <a-col :sm="{span:12}" :xl="{span:6}" style="padding-top: 29px;">
            <a-button type="primary" @click="loadData">查询</a-button>
            <a-button type="primary" @click="handleBatchAudit">批量审核</a-button>
            <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
          </a-col>
        </a-row>
      </a-form>
    </div>
    </a-card>
     <a-alert style="margin-bottom:20px;"  message="调剂审核成功后，需要前往【初试成绩录入】录入学生的业务课成绩" banner />
    <a-card class="card" :bordered="false">
    <a-table
      ref="table"
      size="default"
      rowKey="id"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :alert="options.alert"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
      :pagination="pagination"
      @change="handleTableChange"
      :scroll="{ x: 1500 }"
    >
    <template slot="action" slot-scope="text,record">
        <a @click="handleAudit(record.id)">审核</a>
      </template>
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
    </a-table>

      <!-- 审核 -->
      <audit-handle :AuditHandleVisible="AuditHandleVisible" :info="auditData" @quit="handleCloseAudit" @success="handleSubmitAudit" ></audit-handle>

    </a-card>
</div>
</template>

<script>
// import moment from 'moment'
import AuditHandle from './auditHandle'
import { STable } from '~'
import { mapState } from 'vuex'

const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072']

export default {
  components: {
    STable,
    AuditHandle
  },
  data () {
    return {
      advanced: true,
      AuditHandleVisible: false,
      loading: false,
      data: [],

      pagination:{
        current:1
      },
      // 查询参数
      queryParam: {
        hzfs: 'yx',
        zsnj:''
      },
      postParams: {},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '招生年度',
          dataIndex: 'zsnj'
        },
        {
          title: '准考证号',
          dataIndex: 'ksbh'
        },
        {
          title: '姓名',
          dataIndex: 'ksxm'
        },
        {
          title: '报考院系',
          dataIndex: 'bkyxsmc'
        },
        {
          title: '报考专业代码',
          dataIndex: 'bkzydm'
        },
        {
          title: '报考专业',
          dataIndex: 'bkzymc'
        },
        {
          title: '报考研究方向',
          dataIndex: 'bkyjfxmc'
        },
        {
          title: '报考导师',
          dataIndex: 'bkdsyxm'
        },
        {
          title: '调剂院系',
          dataIndex: 'tjyxmc'
        },
        {
          title: '调剂专业',
          dataIndex: 'tjzymc'
        },
        {
          title: '调剂研究方向',
          dataIndex: 'tjyjfxmc'
        },
        {
          title: '调剂导师',
          dataIndex: 'tjdsyxm'
        },
        {
          title: '调剂状态',
          dataIndex: 'tjzt'
        },
        {
          title: '操作',
          dataIndex: 'cz',
          fixed: 'right',
          width: 120,
          scopedSlots: { customRender: 'action' }
        }
      ],
      selectedRows:[],
      selectedRowKeys:[],
      // custom table alert & rowSelection
      options: {
        alert: { show: false },
        rowSelection: {
          onChange: (selectedRowKeys, selectedRows) => {
            console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows)
          },
          onSelect: (record, selected, selectedRows) => {
            console.log(record, selected, selectedRows)
          },
          onSelectAll: (selected, selectedRows, changeRows) => {
            console.log(selected, selectedRows, changeRows)
          }
        }
      },
      selectMenu: {
        yx: [], // 院系
        zy: [], // 专业
        tjyx:[], // 调剂院系
        tjzy:[] // 调剂专业
      },
      auditData:{
        id:''
      },
      parameter: {},
      recruitEditData: {}
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    this.initSelectMenu()
    this.loadData()
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data,
          tjyx: res[0].data,
        }
        // this.queryParam.bkyxsm=res[0].data[0].dwh;
        // this.$api.base.majorAll({lsdwh: this.queryParam.bkyxsm}).then(res => {
        // this.$set(this.selectMenu, 'zy', res.data)
        // })
        this.queryParam.tjyxdm=res[0].data[0].dwh;
        this.$api.base.majorAll({lsdwh: this.queryParam.tjyxdm}).then(res => {
          this.$set(this.selectMenu, 'tjzy', res.data)
        })
         this.$api.base.getSchoolYear().then(res=>{
        this.queryParam.zsnj=res.data.doctoralAdmissionYear
        this.loadData({
          pageNum:1,
          pageSize:10
        })
      })
      })

    },
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    // 选择院系
    // yxChange (code) {
    //   this.$set(this.queryParam, 'bkzydm', '')
    //    this.$set(this.queryParam,'bkyjfxm','')
    //    this.$set(this.selectMenu,'zy','')
    //    this.$set(this.selectMenu,'fx','')
    //    if(code){
    //   this.$api.base.majorAll({lsdwh: code}).then(res => {
    //     this.$set(this.selectMenu, 'zy', res.data)
    //   })
    //    }
    // },
    zyChange (code) {
       this.$set(this.queryParam,'bkyjfxm','')
       this.$set(this.selectMenu,'fx','')
       if(code){
      let params={
        ssyxm:this.queryParam.bkyxsm,
        sszym:this.queryParam.bkzydm,
        xwccm:3,
        zsxn:this.queryParam.zsnj
      }
      this.$api.base.researchAll(params).then(res=>{
        this.$set(this.selectMenu,'fx',res.data)
      })
       }
    },
    // 选择调剂院系
    yxChange2 (code) {
      this.$set(this.selectMenu,'tjzy','')
      if(code){
      this.$api.base.majorAll({lsdwh: code}).then(res => {
        this.$set(this.selectMenu, 'tjzy', res.data)
      })
      }
    },
    // 加载数据
    loadData(parameter = {}) {
      if(!parameter.pageNum){
         this.pagination.current = 1
         parameter.pageNum = 1
       }
      let params = Object.assign(this.queryParam, parameter)
      this.loading = true;
      this.$api.doctorRecruit.campusAuditList(params).then(res => {
        // console.log(res)
         const pagination = { ...this.pagination
        };
        pagination.total = 0
        if (res.data && res.data.total) {
          pagination.total = res.data.total;
        }
        this.data = []
        this.pagination = pagination;
        if (res.data && res.data.rows.length) {
          this.data = res.data.rows;
        }
        this.loading = false;
      })
    },
    // 分页
			handleTableChange(pagination, filters, sorter) {
				console.log(pagination);
				const pager = { ...this.pagination
				};
				pager.current = pagination.current;
				this.pagination = pager;
				this.loadData({
					pageSize: 10,
					pageNum: pagination.current
				});
			},
    // 审核
    handleAudit (code) {
      console.log('审核',code)
        let chekType = 'single'
        this.auditData = {id:code,chekType:chekType}
        this.AuditHandleVisible = true
    },
    // 多选
    onSelectChange (selectedRowKeys,selectedRows) {
      console.log('selectedRowKeys changed: ', selectedRowKeys);
      this.selectedRows = selectedRows
      this.selectedRowKeys = selectedRowKeys
    },
    // 批量审核
    handleBatchAudit () {
      console.log('批量审核')
      var deleteId = ''
      if (!this.selectedRowKeys.length) {
        this.$message.warning('请选择需要审核的数据')
        return
      }
      if(this.selectedRows && this.selectedRows.length){
        deleteId = this.selectedRows.map(v => {
          return v.id
        }).toString()
      }
      console.log(deleteId)
      var newObj = {
        id:deleteId,
        chekType:'multiply'
      }
      this.auditData = newObj
      console.log(this.auditData)
      this.AuditHandleVisible = true
    },
    // 保存审核
    handleSubmitAudit (d) {
      console.log(d)
      this.AuditHandleVisible = false
      this.loadData({
        pageNum:this.pagination.current,
        pageSize:10
      })
    },
    // 取消审核
    handleCloseAudit () {
      this.AuditHandleVisible = false
    }
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
</style>
